<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">

<title>class Complex - RDoc Documentation</title>


<script src="./js/navigation.js" defer></script>
<script src="./js/search.js" defer></script>
<script src="./js/search_index.js" defer></script>
<script src="./js/searcher.js" defer></script>
<script src="./js/darkfish.js" defer></script>

<script src="./js/jquery-3.2.0.min.js"></script>

<script src="./js/vue.min.js"></script>
<script src="./js/js.cookie.min.js"></script>

<link href="./css/fonts.css" rel="stylesheet">
<link id='rdoccss' href="./css/rdoc.css" rel="stylesheet">
<link href="./css/carbon17.css" rel="stylesheet">

<script type="text/javascript">
  var rdoc_rel_prefix = "./";
  var index_rel_prefix = "./";
  var darkModeCsseHref = "./css/rdoc-dm.css"
  var defaultModeCssHref = "./css/rdoc.css"
  // var cssDarkmode = Cookies.get('darkmode');
  
  if( Cookies.get("darkmode") == "true") {
	$('#rdoccss').attr("href", darkModeCsseHref);
}

//  https://cssdeck.com/blog/simple-jquery-stylesheet-switcher/

document.write('<style type="text/css">body{display:none}</style>');

</script>


</head>
<body id="top" role="document" class="class">
  <!-- this is class.html -->

  <div id='actionbar' >
    <div class='wrapper mdiv'>
      <ul class='grids g0'></ul>
    </div> 
    <!-- VERSION HEADER for 3.3.0-preview2 NOT FOUND -->
  </div> <!-- end action bar -->

  <div class='wrapper hdiv'>

    


    <nav id='vapp' role="navigation">
    <div id="project-navigation">
      <div id="home-section" role="region" title="Quick navigation" class="nav-section">
  <h2><a href="./index.html" rel="home">Home</a></h2>

  <div id="table-of-contents-navigation"  >
    <a href="./table_of_contents.html#pages">Pages</a>
    <a href="./table_of_contents.html#classes">Classes</a>
    <a href="./table_of_contents.html#methods">Methods</a>
  </div>
</div>

      <div id="search-section" role="search" class="project-section initially-hidden">
  <form action="#" method="get" accept-charset="utf-8">
    <div id="search-field-wrapper">
      <input id="search-field" role="combobox" aria-label="Search"
             aria-autocomplete="list" aria-controls="search-results"
             type="text" name="search" placeholder="Search" spellcheck="false"
             title="Type to search, Up and Down to navigate, Enter to load">
    </div>

    <ul id="search-results" aria-label="Search Results"
        aria-busy="false" aria-expanded="false"
        aria-atomic="false" class="initially-hidden"></ul>
  </form>
</div>

    </div>


    

    <button id='toggleThing' @click="toggleNav()" >Show/hide navigation</button>
    <div :class="isOpen ? 'block' : 'hidden' " id='toggleMe'>
      <div id="class-metadata">
        
        
<div id="parent-class-section" class="nav-section">
  <h3>Parent</h3>

  <p class="link"><a href="Numeric.html">Numeric</a>
</div>

        
        
        
<!-- Method Quickref -->
<div id="method-list-section" class="nav-section">
  <h3>Methods</h3>

  <ul class="link-list" role="directory">
    <li ><a href="#method-c-polar">::polar</a>
    <li ><a href="#method-c-rect">::rect</a>
    <li ><a href="#method-c-rectangular">::rectangular</a>
    <li ><a href="#method-i-2A">#*</a>
    <li ><a href="#method-i-2A-2A">#**</a>
    <li ><a href="#method-i-2B">#+</a>
    <li ><a href="#method-i-2D">#-</a>
    <li ><a href="#method-i-2D-40">#-@</a>
    <li ><a href="#method-i-2F">#/</a>
    <li ><a href="#method-i-3C-3D-3E">#&lt;=&gt;</a>
    <li ><a href="#method-i-3D-3D">#==</a>
    <li ><a href="#method-i-abs">#abs</a>
    <li ><a href="#method-i-abs2">#abs2</a>
    <li ><a href="#method-i-angle">#angle</a>
    <li ><a href="#method-i-arg">#arg</a>
    <li ><a href="#method-i-conj">#conj</a>
    <li ><a href="#method-i-conjugate">#conjugate</a>
    <li ><a href="#method-i-denominator">#denominator</a>
    <li ><a href="#method-i-fdiv">#fdiv</a>
    <li ><a href="#method-i-finite-3F">#finite?</a>
    <li ><a href="#method-i-hash">#hash</a>
    <li ><a href="#method-i-imag">#imag</a>
    <li ><a href="#method-i-imaginary">#imaginary</a>
    <li ><a href="#method-i-infinite-3F">#infinite?</a>
    <li ><a href="#method-i-inspect">#inspect</a>
    <li ><a href="#method-i-magnitude">#magnitude</a>
    <li ><a href="#method-i-numerator">#numerator</a>
    <li ><a href="#method-i-phase">#phase</a>
    <li ><a href="#method-i-polar">#polar</a>
    <li ><a href="#method-i-quo">#quo</a>
    <li ><a href="#method-i-rationalize">#rationalize</a>
    <li ><a href="#method-i-real">#real</a>
    <li ><a href="#method-i-real-3F">#real?</a>
    <li ><a href="#method-i-rect">#rect</a>
    <li ><a href="#method-i-rectangular">#rectangular</a>
    <li ><a href="#method-i-to_c">#to_c</a>
    <li ><a href="#method-i-to_f">#to_f</a>
    <li ><a href="#method-i-to_i">#to_i</a>
    <li ><a href="#method-i-to_r">#to_r</a>
    <li ><a href="#method-i-to_s">#to_s</a>
  </ul>
</div>

      </div>
     </div>
    </nav>


    <div id='extraz'><div class='adzbox-index'  >
      
     </div>         
    </div>

    <main role="main" aria-labelledby="class-Complex">
    <h1 id="class-Complex" class="class">
      class Complex
    </h1>

    <section class="description">
    
<p>A complex number can be represented as a paired real number with imaginary unit; a+bi.  Where a is real part, b is imaginary part and i is imaginary unit.  Real a equals complex a+0i mathematically.</p>

<p>You can create a Complex object explicitly with:</p>
<ul><li>
<p>A <a href="syntax/literals_rdoc.html#label-Complex+Literals">complex literal</a>.</p>
</li></ul>

<p>You can convert certain objects to Complex objects with:</p>
<ul><li>
<p>Method <a href="Kernel.html#method-i-Complex"><code>Complex</code></a>.</p>
</li></ul>

<p><a href="Complex.html"><code>Complex</code></a> object can be created as literal, and also by using <a href="Kernel.html#method-i-Complex"><code>Kernel#Complex</code></a>, <a href="Complex.html#method-c-rect"><code>Complex::rect</code></a>, <a href="Complex.html#method-c-polar"><code>Complex::polar</code></a> or <a href="Complex.html#method-i-to_c"><code>to_c</code></a> method.</p>

<pre class="ruby"><span class="ruby-value">2</span><span class="ruby-value">+1i</span>                 <span class="ruby-comment">#=&gt; (2+1i)</span>
<span class="ruby-constant">Complex</span>(<span class="ruby-value">1</span>)           <span class="ruby-comment">#=&gt; (1+0i)</span>
<span class="ruby-constant">Complex</span>(<span class="ruby-value">2</span>, <span class="ruby-value">3</span>)        <span class="ruby-comment">#=&gt; (2+3i)</span>
<span class="ruby-constant">Complex</span>.<span class="ruby-identifier">polar</span>(<span class="ruby-value">2</span>, <span class="ruby-value">3</span>)  <span class="ruby-comment">#=&gt; (-1.9799849932008908+0.2822400161197344i)</span>
<span class="ruby-value">3</span>.<span class="ruby-identifier">to_c</span>               <span class="ruby-comment">#=&gt; (3+0i)</span>
</pre>

<p>You can also create complex object from floating-point numbers or strings.</p>

<pre class="ruby"><span class="ruby-constant">Complex</span>(<span class="ruby-value">0.3</span>)         <span class="ruby-comment">#=&gt; (0.3+0i)</span>
<span class="ruby-constant">Complex</span>(<span class="ruby-string">&#39;0.3-0.5i&#39;</span>)  <span class="ruby-comment">#=&gt; (0.3-0.5i)</span>
<span class="ruby-constant">Complex</span>(<span class="ruby-string">&#39;2/3+3/4i&#39;</span>)  <span class="ruby-comment">#=&gt; ((2/3)+(3/4)*i)</span>
<span class="ruby-constant">Complex</span>(<span class="ruby-string">&#39;1@2&#39;</span>)       <span class="ruby-comment">#=&gt; (-0.4161468365471424+0.9092974268256817i)</span>

<span class="ruby-value">0.3</span>.<span class="ruby-identifier">to_c</span>             <span class="ruby-comment">#=&gt; (0.3+0i)</span>
<span class="ruby-string">&#39;0.3-0.5i&#39;</span>.<span class="ruby-identifier">to_c</span>      <span class="ruby-comment">#=&gt; (0.3-0.5i)</span>
<span class="ruby-string">&#39;2/3+3/4i&#39;</span>.<span class="ruby-identifier">to_c</span>      <span class="ruby-comment">#=&gt; ((2/3)+(3/4)*i)</span>
<span class="ruby-string">&#39;1@2&#39;</span>.<span class="ruby-identifier">to_c</span>           <span class="ruby-comment">#=&gt; (-0.4161468365471424+0.9092974268256817i)</span>
</pre>

<p>A complex object is either an exact or an inexact number.</p>

<pre class="ruby"><span class="ruby-constant">Complex</span>(<span class="ruby-value">1</span>, <span class="ruby-value">1</span>) <span class="ruby-operator">/</span> <span class="ruby-value">2</span>    <span class="ruby-comment">#=&gt; ((1/2)+(1/2)*i)</span>
<span class="ruby-constant">Complex</span>(<span class="ruby-value">1</span>, <span class="ruby-value">1</span>) <span class="ruby-operator">/</span> <span class="ruby-value">2.0</span>  <span class="ruby-comment">#=&gt; (0.5+0.5i)</span>
</pre>

    </section>

      <section id="5Buntitled-5D" class="documentation-section">


      <section class="constants-list">
      <header>
      <h3>Constants</h3>
      </header>
      <dl>
          <dt id="I">I
          <dd><p>The imaginary unit.</p>
        </dl>
        </section>



                <section id="public-class-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Public Class Methods</h3>
                </header>

                  <div id="method-c-polar" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          polar(abs[, arg])  &rarr;  complex
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns a complex object which denotes the given polar form.</p>

<pre class="ruby"><span class="ruby-constant">Complex</span>.<span class="ruby-identifier">polar</span>(<span class="ruby-value">3</span>, <span class="ruby-value">0</span>)            <span class="ruby-comment">#=&gt; (3.0+0.0i)</span>
<span class="ruby-constant">Complex</span>.<span class="ruby-identifier">polar</span>(<span class="ruby-value">3</span>, <span class="ruby-constant">Math</span><span class="ruby-operator">::</span><span class="ruby-constant">PI</span><span class="ruby-operator">/</span><span class="ruby-value">2</span>)   <span class="ruby-comment">#=&gt; (1.836909530733566e-16+3.0i)</span>
<span class="ruby-constant">Complex</span>.<span class="ruby-identifier">polar</span>(<span class="ruby-value">3</span>, <span class="ruby-constant">Math</span><span class="ruby-operator">::</span><span class="ruby-constant">PI</span>)     <span class="ruby-comment">#=&gt; (-3.0+3.673819061467132e-16i)</span>
<span class="ruby-constant">Complex</span>.<span class="ruby-identifier">polar</span>(<span class="ruby-value">3</span>, <span class="ruby-operator">-</span><span class="ruby-constant">Math</span><span class="ruby-operator">::</span><span class="ruby-constant">PI</span><span class="ruby-operator">/</span><span class="ruby-value">2</span>)  <span class="ruby-comment">#=&gt; (1.836909530733566e-16-3.0i)</span>
</pre>

                              <div class="method-source-code" id="polar-source">
            <pre>static VALUE
nucomp_s_polar(int argc, VALUE *argv, VALUE klass)
{
    VALUE abs, arg;

    argc = rb_scan_args(argc, argv, &quot;11&quot;, &amp;abs, &amp;arg);
    abs = nucomp_real_check(abs);
    if (argc == 2) {
        arg = nucomp_real_check(arg);
    }
    else {
        arg = ZERO;
    }
    return f_complex_polar_real(klass, abs, arg);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-rect" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          rect(real[, imag])         &rarr;  complex
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          rectangular(real[, imag])  &rarr;  complex
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Returns a complex object which denotes the given rectangular form.</p>

<pre class="ruby"><span class="ruby-constant">Complex</span>.<span class="ruby-identifier">rectangular</span>(<span class="ruby-value">1</span>, <span class="ruby-value">2</span>)  <span class="ruby-comment">#=&gt; (1+2i)</span>
</pre>

                              <div class="method-source-code" id="rect-source">
            <pre>static VALUE
nucomp_s_new(int argc, VALUE *argv, VALUE klass)
{
    VALUE real, imag;

    switch (rb_scan_args(argc, argv, &quot;11&quot;, &amp;real, &amp;imag)) {
      case 1:
        real = nucomp_real_check(real);
        imag = ZERO;
        break;
      default:
        real = nucomp_real_check(real);
        imag = nucomp_real_check(imag);
        break;
    }

    return nucomp_s_new_internal(klass, real, imag);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-rectangular" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          rect(real[, imag])         &rarr;  complex
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          rectangular(real[, imag])  &rarr;  complex
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Returns a complex object which denotes the given rectangular form.</p>

<pre class="ruby"><span class="ruby-constant">Complex</span>.<span class="ruby-identifier">rectangular</span>(<span class="ruby-value">1</span>, <span class="ruby-value">2</span>)  <span class="ruby-comment">#=&gt; (1+2i)</span>
</pre>

                              <div class="method-source-code" id="rectangular-source">
            <pre>static VALUE
nucomp_s_new(int argc, VALUE *argv, VALUE klass)
{
    VALUE real, imag;

    switch (rb_scan_args(argc, argv, &quot;11&quot;, &amp;real, &amp;imag)) {
      case 1:
        real = nucomp_real_check(real);
        imag = ZERO;
        break;
      default:
        real = nucomp_real_check(real);
        imag = nucomp_real_check(imag);
        break;
    }

    return nucomp_s_new_internal(klass, real, imag);
}</pre>
                              </div>
                            </div>


                          </div>

                          </section>

                <section id="public-instance-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Public Instance Methods</h3>
                </header>

                  <div id="method-i-2A" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          cmp * numeric  &rarr;  complex
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Performs multiplication.</p>

<pre class="ruby"><span class="ruby-constant">Complex</span>(<span class="ruby-value">2</span>, <span class="ruby-value">3</span>)  <span class="ruby-operator">*</span> <span class="ruby-constant">Complex</span>(<span class="ruby-value">2</span>, <span class="ruby-value">3</span>)   <span class="ruby-comment">#=&gt; (-5+12i)</span>
<span class="ruby-constant">Complex</span>(<span class="ruby-value">900</span>)   <span class="ruby-operator">*</span> <span class="ruby-constant">Complex</span>(<span class="ruby-value">1</span>)      <span class="ruby-comment">#=&gt; (900+0i)</span>
<span class="ruby-constant">Complex</span>(<span class="ruby-value">-2</span>, <span class="ruby-value">9</span>) <span class="ruby-operator">*</span> <span class="ruby-constant">Complex</span>(<span class="ruby-value">-9</span>, <span class="ruby-value">2</span>)  <span class="ruby-comment">#=&gt; (0-85i)</span>
<span class="ruby-constant">Complex</span>(<span class="ruby-value">9</span>, <span class="ruby-value">8</span>)  <span class="ruby-operator">*</span> <span class="ruby-value">4</span>               <span class="ruby-comment">#=&gt; (36+32i)</span>
<span class="ruby-constant">Complex</span>(<span class="ruby-value">20</span>, <span class="ruby-value">9</span>) <span class="ruby-operator">*</span> <span class="ruby-value">9.8</span>             <span class="ruby-comment">#=&gt; (196.0+88.2i)</span>
</pre>

                              <div class="method-source-code" id="2A-source">
            <pre>VALUE
rb_complex_mul(VALUE self, VALUE other)
{
    if (RB_TYPE_P(other, T_COMPLEX)) {
        VALUE real, imag;
        get_dat2(self, other);

        comp_mul(adat-&gt;real, adat-&gt;imag, bdat-&gt;real, bdat-&gt;imag, &amp;real, &amp;imag);

        return f_complex_new2(CLASS_OF(self), real, imag);
    }
    if (k_numeric_p(other) &amp;&amp; f_real_p(other)) {
        get_dat1(self);

        return f_complex_new2(CLASS_OF(self),
                              f_mul(dat-&gt;real, other),
                              f_mul(dat-&gt;imag, other));
    }
    return rb_num_coerce_bin(self, other, &#39;*&#39;);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-2A-2A" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          cmp ** numeric  &rarr;  complex
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Performs exponentiation.</p>

<pre class="ruby"><span class="ruby-constant">Complex</span>(<span class="ruby-string">&#39;i&#39;</span>) <span class="ruby-operator">**</span> <span class="ruby-value">2</span>              <span class="ruby-comment">#=&gt; (-1+0i)</span>
<span class="ruby-constant">Complex</span>(<span class="ruby-value">-8</span>) <span class="ruby-operator">**</span> <span class="ruby-constant">Rational</span>(<span class="ruby-value">1</span>, <span class="ruby-value">3</span>)  <span class="ruby-comment">#=&gt; (1.0000000000000002+1.7320508075688772i)</span>
</pre>

                              <div class="method-source-code" id="2A-2A-source">
            <pre>VALUE
rb_complex_pow(VALUE self, VALUE other)
{
    if (k_numeric_p(other) &amp;&amp; k_exact_zero_p(other))
        return f_complex_new_bang1(CLASS_OF(self), ONE);

    if (RB_TYPE_P(other, T_RATIONAL) &amp;&amp; RRATIONAL(other)-&gt;den == LONG2FIX(1))
        other = RRATIONAL(other)-&gt;num; /* c14n */

    if (RB_TYPE_P(other, T_COMPLEX)) {
        get_dat1(other);

        if (k_exact_zero_p(dat-&gt;imag))
            other = dat-&gt;real; /* c14n */
    }

    if (RB_TYPE_P(other, T_COMPLEX)) {
        VALUE r, theta, nr, ntheta;

        get_dat1(other);

        r = f_abs(self);
        theta = f_arg(self);

        nr = m_exp_bang(f_sub(f_mul(dat-&gt;real, m_log_bang(r)),
                              f_mul(dat-&gt;imag, theta)));
        ntheta = f_add(f_mul(theta, dat-&gt;real),
                       f_mul(dat-&gt;imag, m_log_bang(r)));
        return f_complex_polar(CLASS_OF(self), nr, ntheta);
    }
    if (FIXNUM_P(other)) {
        long n = FIX2LONG(other);
        if (n == 0) {
            return nucomp_s_new_internal(CLASS_OF(self), ONE, ZERO);
        }
        if (n &lt; 0) {
            self = f_reciprocal(self);
            other = rb_int_uminus(other);
            n = -n;
        }
        {
            get_dat1(self);
            VALUE xr = dat-&gt;real, xi = dat-&gt;imag, zr = xr, zi = xi;

            if (f_zero_p(xi)) {
                zr = rb_num_pow(zr, other);
            }
            else if (f_zero_p(xr)) {
                zi = rb_num_pow(zi, other);
                if (n &amp; 2) zi = f_negate(zi);
                if (!(n &amp; 1)) {
                    VALUE tmp = zr;
                    zr = zi;
                    zi = tmp;
                }
            }
            else {
                while (--n) {
                    long q, r;

                    for (; q = n / 2, r = n % 2, r == 0; n = q) {
                        VALUE tmp = f_sub(f_mul(xr, xr), f_mul(xi, xi));
                        xi = f_mul(f_mul(TWO, xr), xi);
                        xr = tmp;
                    }
                    comp_mul(zr, zi, xr, xi, &amp;zr, &amp;zi);
                }
            }
            return nucomp_s_new_internal(CLASS_OF(self), zr, zi);
        }
    }
    if (k_numeric_p(other) &amp;&amp; f_real_p(other)) {
        VALUE r, theta;

        if (RB_BIGNUM_TYPE_P(other))
            rb_warn(&quot;in a**b, b may be too big&quot;);

        r = f_abs(self);
        theta = f_arg(self);

        return f_complex_polar(CLASS_OF(self), f_expt(r, other),
                               f_mul(theta, other));
    }
    return rb_num_coerce_bin(self, other, id_expt);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-2B" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          cmp + numeric  &rarr;  complex
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Performs addition.</p>

<pre class="ruby"><span class="ruby-constant">Complex</span>(<span class="ruby-value">2</span>, <span class="ruby-value">3</span>)  <span class="ruby-operator">+</span> <span class="ruby-constant">Complex</span>(<span class="ruby-value">2</span>, <span class="ruby-value">3</span>)   <span class="ruby-comment">#=&gt; (4+6i)</span>
<span class="ruby-constant">Complex</span>(<span class="ruby-value">900</span>)   <span class="ruby-operator">+</span> <span class="ruby-constant">Complex</span>(<span class="ruby-value">1</span>)      <span class="ruby-comment">#=&gt; (901+0i)</span>
<span class="ruby-constant">Complex</span>(<span class="ruby-value">-2</span>, <span class="ruby-value">9</span>) <span class="ruby-operator">+</span> <span class="ruby-constant">Complex</span>(<span class="ruby-value">-9</span>, <span class="ruby-value">2</span>)  <span class="ruby-comment">#=&gt; (-11+11i)</span>
<span class="ruby-constant">Complex</span>(<span class="ruby-value">9</span>, <span class="ruby-value">8</span>)  <span class="ruby-operator">+</span> <span class="ruby-value">4</span>               <span class="ruby-comment">#=&gt; (13+8i)</span>
<span class="ruby-constant">Complex</span>(<span class="ruby-value">20</span>, <span class="ruby-value">9</span>) <span class="ruby-operator">+</span> <span class="ruby-value">9.8</span>             <span class="ruby-comment">#=&gt; (29.8+9i)</span>
</pre>

                              <div class="method-source-code" id="2B-source">
            <pre>VALUE
rb_complex_plus(VALUE self, VALUE other)
{
    if (RB_TYPE_P(other, T_COMPLEX)) {
        VALUE real, imag;

        get_dat2(self, other);

        real = f_add(adat-&gt;real, bdat-&gt;real);
        imag = f_add(adat-&gt;imag, bdat-&gt;imag);

        return f_complex_new2(CLASS_OF(self), real, imag);
    }
    if (k_numeric_p(other) &amp;&amp; f_real_p(other)) {
        get_dat1(self);

        return f_complex_new2(CLASS_OF(self),
                              f_add(dat-&gt;real, other), dat-&gt;imag);
    }
    return rb_num_coerce_bin(self, other, &#39;+&#39;);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-2D" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          cmp - numeric  &rarr;  complex
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Performs subtraction.</p>

<pre class="ruby"><span class="ruby-constant">Complex</span>(<span class="ruby-value">2</span>, <span class="ruby-value">3</span>)  <span class="ruby-operator">-</span> <span class="ruby-constant">Complex</span>(<span class="ruby-value">2</span>, <span class="ruby-value">3</span>)   <span class="ruby-comment">#=&gt; (0+0i)</span>
<span class="ruby-constant">Complex</span>(<span class="ruby-value">900</span>)   <span class="ruby-operator">-</span> <span class="ruby-constant">Complex</span>(<span class="ruby-value">1</span>)      <span class="ruby-comment">#=&gt; (899+0i)</span>
<span class="ruby-constant">Complex</span>(<span class="ruby-value">-2</span>, <span class="ruby-value">9</span>) <span class="ruby-operator">-</span> <span class="ruby-constant">Complex</span>(<span class="ruby-value">-9</span>, <span class="ruby-value">2</span>)  <span class="ruby-comment">#=&gt; (7+7i)</span>
<span class="ruby-constant">Complex</span>(<span class="ruby-value">9</span>, <span class="ruby-value">8</span>)  <span class="ruby-operator">-</span> <span class="ruby-value">4</span>               <span class="ruby-comment">#=&gt; (5+8i)</span>
<span class="ruby-constant">Complex</span>(<span class="ruby-value">20</span>, <span class="ruby-value">9</span>) <span class="ruby-operator">-</span> <span class="ruby-value">9.8</span>             <span class="ruby-comment">#=&gt; (10.2+9i)</span>
</pre>

                              <div class="method-source-code" id="2D-source">
            <pre>VALUE
rb_complex_minus(VALUE self, VALUE other)
{
    if (RB_TYPE_P(other, T_COMPLEX)) {
        VALUE real, imag;

        get_dat2(self, other);

        real = f_sub(adat-&gt;real, bdat-&gt;real);
        imag = f_sub(adat-&gt;imag, bdat-&gt;imag);

        return f_complex_new2(CLASS_OF(self), real, imag);
    }
    if (k_numeric_p(other) &amp;&amp; f_real_p(other)) {
        get_dat1(self);

        return f_complex_new2(CLASS_OF(self),
                              f_sub(dat-&gt;real, other), dat-&gt;imag);
    }
    return rb_num_coerce_bin(self, other, &#39;-&#39;);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-2D-40" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          -cmp  &rarr;  complex
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns negation of the value.</p>

<pre class="ruby"><span class="ruby-operator">-</span><span class="ruby-constant">Complex</span>(<span class="ruby-value">1</span>, <span class="ruby-value">2</span>)  <span class="ruby-comment">#=&gt; (-1-2i)</span>
</pre>

                              <div class="method-source-code" id="2D-40-source">
            <pre>VALUE
rb_complex_uminus(VALUE self)
{
    get_dat1(self);
    return f_complex_new2(CLASS_OF(self),
                          f_negate(dat-&gt;real), f_negate(dat-&gt;imag));
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-2F" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          cmp / numeric     &rarr;  complex
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          quo(numeric)  &rarr;  complex
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Performs division.</p>

<pre class="ruby"><span class="ruby-constant">Complex</span>(<span class="ruby-value">2</span>, <span class="ruby-value">3</span>)  <span class="ruby-operator">/</span> <span class="ruby-constant">Complex</span>(<span class="ruby-value">2</span>, <span class="ruby-value">3</span>)   <span class="ruby-comment">#=&gt; ((1/1)+(0/1)*i)</span>
<span class="ruby-constant">Complex</span>(<span class="ruby-value">900</span>)   <span class="ruby-operator">/</span> <span class="ruby-constant">Complex</span>(<span class="ruby-value">1</span>)      <span class="ruby-comment">#=&gt; ((900/1)+(0/1)*i)</span>
<span class="ruby-constant">Complex</span>(<span class="ruby-value">-2</span>, <span class="ruby-value">9</span>) <span class="ruby-operator">/</span> <span class="ruby-constant">Complex</span>(<span class="ruby-value">-9</span>, <span class="ruby-value">2</span>)  <span class="ruby-comment">#=&gt; ((36/85)-(77/85)*i)</span>
<span class="ruby-constant">Complex</span>(<span class="ruby-value">9</span>, <span class="ruby-value">8</span>)  <span class="ruby-operator">/</span> <span class="ruby-value">4</span>               <span class="ruby-comment">#=&gt; ((9/4)+(2/1)*i)</span>
<span class="ruby-constant">Complex</span>(<span class="ruby-value">20</span>, <span class="ruby-value">9</span>) <span class="ruby-operator">/</span> <span class="ruby-value">9.8</span>             <span class="ruby-comment">#=&gt; (2.0408163265306123+0.9183673469387754i)</span>
</pre>

                              <div class="method-source-code" id="2F-source">
            <pre>VALUE
rb_complex_div(VALUE self, VALUE other)
{
    return f_divide(self, other, f_quo, id_quo);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-3C-3D-3E" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          cmp &lt;=&gt; object  &rarr;  0, 1, -1, or nil
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>If <code>cmp</code>‘s imaginary part is zero, and <code>object</code> is also a real number (or a <a href="Complex.html"><code>Complex</code></a> number where the imaginary part is zero), compare the real part of <code>cmp</code> to object.  Otherwise, return nil.</p>

<pre class="ruby"><span class="ruby-constant">Complex</span>(<span class="ruby-value">2</span>, <span class="ruby-value">3</span>)  <span class="ruby-operator">&lt;=&gt;</span> <span class="ruby-constant">Complex</span>(<span class="ruby-value">2</span>, <span class="ruby-value">3</span>)   <span class="ruby-comment">#=&gt; nil</span>
<span class="ruby-constant">Complex</span>(<span class="ruby-value">2</span>, <span class="ruby-value">3</span>)  <span class="ruby-operator">&lt;=&gt;</span> <span class="ruby-value">1</span>               <span class="ruby-comment">#=&gt; nil</span>
<span class="ruby-constant">Complex</span>(<span class="ruby-value">2</span>)     <span class="ruby-operator">&lt;=&gt;</span> <span class="ruby-value">1</span>               <span class="ruby-comment">#=&gt; 1</span>
<span class="ruby-constant">Complex</span>(<span class="ruby-value">2</span>)     <span class="ruby-operator">&lt;=&gt;</span> <span class="ruby-value">2</span>               <span class="ruby-comment">#=&gt; 0</span>
<span class="ruby-constant">Complex</span>(<span class="ruby-value">2</span>)     <span class="ruby-operator">&lt;=&gt;</span> <span class="ruby-value">3</span>               <span class="ruby-comment">#=&gt; -1</span>
</pre>

                              <div class="method-source-code" id="3C-3D-3E-source">
            <pre>static VALUE
nucomp_cmp(VALUE self, VALUE other)
{
    if (!k_numeric_p(other)) {
        return rb_num_coerce_cmp(self, other, idCmp);
    }
    if (!nucomp_real_p(self)) {
        return Qnil;
    }
    if (RB_TYPE_P(other, T_COMPLEX)) {
        if (nucomp_real_p(other)) {
            get_dat2(self, other);
            return rb_funcall(adat-&gt;real, idCmp, 1, bdat-&gt;real);
        }
    }
    else {
        get_dat1(self);
        if (f_real_p(other)) {
            return rb_funcall(dat-&gt;real, idCmp, 1, other);
        }
        else {
            return rb_num_coerce_cmp(dat-&gt;real, other, idCmp);
        }
    }
    return Qnil;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-3D-3D" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          cmp == object  &rarr;  true or false
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns true if cmp equals object numerically.</p>

<pre class="ruby"><span class="ruby-constant">Complex</span>(<span class="ruby-value">2</span>, <span class="ruby-value">3</span>)  <span class="ruby-operator">==</span> <span class="ruby-constant">Complex</span>(<span class="ruby-value">2</span>, <span class="ruby-value">3</span>)   <span class="ruby-comment">#=&gt; true</span>
<span class="ruby-constant">Complex</span>(<span class="ruby-value">5</span>)     <span class="ruby-operator">==</span> <span class="ruby-value">5</span>               <span class="ruby-comment">#=&gt; true</span>
<span class="ruby-constant">Complex</span>(<span class="ruby-value">0</span>)     <span class="ruby-operator">==</span> <span class="ruby-value">0.0</span>             <span class="ruby-comment">#=&gt; true</span>
<span class="ruby-constant">Complex</span>(<span class="ruby-string">&#39;1/3&#39;</span>) <span class="ruby-operator">==</span> <span class="ruby-value">0.33</span>            <span class="ruby-comment">#=&gt; false</span>
<span class="ruby-constant">Complex</span>(<span class="ruby-string">&#39;1/2&#39;</span>) <span class="ruby-operator">==</span> <span class="ruby-string">&#39;1/2&#39;</span>           <span class="ruby-comment">#=&gt; false</span>
</pre>

                              <div class="method-source-code" id="3D-3D-source">
            <pre>static VALUE
nucomp_eqeq_p(VALUE self, VALUE other)
{
    if (RB_TYPE_P(other, T_COMPLEX)) {
        get_dat2(self, other);

        return RBOOL(f_eqeq_p(adat-&gt;real, bdat-&gt;real) &amp;&amp;
                          f_eqeq_p(adat-&gt;imag, bdat-&gt;imag));
    }
    if (k_numeric_p(other) &amp;&amp; f_real_p(other)) {
        get_dat1(self);

        return RBOOL(f_eqeq_p(dat-&gt;real, other) &amp;&amp; f_zero_p(dat-&gt;imag));
    }
    return RBOOL(f_eqeq_p(other, self));
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-abs" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          abs        &rarr;  real
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the absolute part of its polar form.</p>

<pre class="ruby"><span class="ruby-constant">Complex</span>(<span class="ruby-value">-1</span>).<span class="ruby-identifier">abs</span>         <span class="ruby-comment">#=&gt; 1</span>
<span class="ruby-constant">Complex</span>(<span class="ruby-value">3.0</span>, <span class="ruby-value">-4.0</span>).<span class="ruby-identifier">abs</span>  <span class="ruby-comment">#=&gt; 5.0</span>
</pre>

                              <div class="method-source-code" id="abs-source">
            <pre>VALUE
rb_complex_abs(VALUE self)
{
    get_dat1(self);

    if (f_zero_p(dat-&gt;real)) {
        VALUE a = f_abs(dat-&gt;imag);
        if (RB_FLOAT_TYPE_P(dat-&gt;real) &amp;&amp; !RB_FLOAT_TYPE_P(dat-&gt;imag))
            a = f_to_f(a);
        return a;
    }
    if (f_zero_p(dat-&gt;imag)) {
        VALUE a = f_abs(dat-&gt;real);
        if (!RB_FLOAT_TYPE_P(dat-&gt;real) &amp;&amp; RB_FLOAT_TYPE_P(dat-&gt;imag))
            a = f_to_f(a);
        return a;
    }
    return rb_math_hypot(dat-&gt;real, dat-&gt;imag);
}</pre>
                              </div>
                            </div>

                            <div class="aliases">
                              Also aliased as: <a href="Complex.html#method-i-magnitude">magnitude</a>
                            </div>

                          </div>

                  <div id="method-i-abs2" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          abs2  &rarr;  real
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns square of the absolute value.</p>

<pre class="ruby"><span class="ruby-constant">Complex</span>(<span class="ruby-value">-1</span>).<span class="ruby-identifier">abs2</span>         <span class="ruby-comment">#=&gt; 1</span>
<span class="ruby-constant">Complex</span>(<span class="ruby-value">3.0</span>, <span class="ruby-value">-4.0</span>).<span class="ruby-identifier">abs2</span>  <span class="ruby-comment">#=&gt; 25.0</span>
</pre>

                              <div class="method-source-code" id="abs2-source">
            <pre>static VALUE
nucomp_abs2(VALUE self)
{
    get_dat1(self);
    return f_add(f_mul(dat-&gt;real, dat-&gt;real),
                 f_mul(dat-&gt;imag, dat-&gt;imag));
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-angle" class="method-detail method-alias">
                      <div class="method-heading">
                        <span class="method-callseq">
                          angle  &rarr;  float
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Returns the angle part of its polar form.</p>

<pre class="ruby"><span class="ruby-constant">Complex</span>.<span class="ruby-identifier">polar</span>(<span class="ruby-value">3</span>, <span class="ruby-constant">Math</span><span class="ruby-operator">::</span><span class="ruby-constant">PI</span><span class="ruby-operator">/</span><span class="ruby-value">2</span>).<span class="ruby-identifier">arg</span>  <span class="ruby-comment">#=&gt; 1.5707963267948966</span>
</pre>

                            </div>


                            <div class="aliases">
                              Alias for: <a href="Complex.html#method-i-arg">arg</a>
                            </div>
                          </div>

                  <div id="method-i-arg" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          arg    &rarr;  float
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the angle part of its polar form.</p>

<pre class="ruby"><span class="ruby-constant">Complex</span>.<span class="ruby-identifier">polar</span>(<span class="ruby-value">3</span>, <span class="ruby-constant">Math</span><span class="ruby-operator">::</span><span class="ruby-constant">PI</span><span class="ruby-operator">/</span><span class="ruby-value">2</span>).<span class="ruby-identifier">arg</span>  <span class="ruby-comment">#=&gt; 1.5707963267948966</span>
</pre>

                              <div class="method-source-code" id="arg-source">
            <pre>VALUE
rb_complex_arg(VALUE self)
{
    get_dat1(self);
    return rb_math_atan2(dat-&gt;imag, dat-&gt;real);
}</pre>
                              </div>
                            </div>

                            <div class="aliases">
                              Also aliased as: <a href="Complex.html#method-i-angle">angle</a>, <a href="Complex.html#method-i-phase">phase</a>
                            </div>

                          </div>

                  <div id="method-i-conj" class="method-detail method-alias">
                      <div class="method-heading">
                        <span class="method-callseq">
                          conj       &rarr;  complex
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Returns the complex conjugate.</p>

<pre class="ruby"><span class="ruby-constant">Complex</span>(<span class="ruby-value">1</span>, <span class="ruby-value">2</span>).<span class="ruby-identifier">conjugate</span>  <span class="ruby-comment">#=&gt; (1-2i)</span>
</pre>

                            </div>


                            <div class="aliases">
                              Alias for: <a href="Complex.html#method-i-conjugate">conjugate</a>
                            </div>
                          </div>

                  <div id="method-i-conjugate" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">conjugate</span><span
                                class="method-args">  -&gt;  complex</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the complex conjugate.</p>

<pre class="ruby"><span class="ruby-constant">Complex</span>(<span class="ruby-value">1</span>, <span class="ruby-value">2</span>).<span class="ruby-identifier">conjugate</span>  <span class="ruby-comment">#=&gt; (1-2i)</span>
</pre>

                              <div class="method-source-code" id="conjugate-source">
            <pre>VALUE
rb_complex_conjugate(VALUE self)
{
    get_dat1(self);
    return f_complex_new2(CLASS_OF(self), dat-&gt;real, f_negate(dat-&gt;imag));
}</pre>
                              </div>
                            </div>

                            <div class="aliases">
                              Also aliased as: <a href="Complex.html#method-i-conj">conj</a>
                            </div>

                          </div>

                  <div id="method-i-denominator" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          denominator  &rarr;  integer
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the denominator (lcm of both denominator - real and imag).</p>

<p>See numerator.</p>

                              <div class="method-source-code" id="denominator-source">
            <pre>static VALUE
nucomp_denominator(VALUE self)
{
    get_dat1(self);
    return rb_lcm(f_denominator(dat-&gt;real), f_denominator(dat-&gt;imag));
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-fdiv" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          fdiv(numeric)  &rarr;  complex
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Performs division as each part is a float, never returns a float.</p>

<pre class="ruby"><span class="ruby-constant">Complex</span>(<span class="ruby-value">11</span>, <span class="ruby-value">22</span>).<span class="ruby-identifier">fdiv</span>(<span class="ruby-value">3</span>)  <span class="ruby-comment">#=&gt; (3.6666666666666665+7.333333333333333i)</span>
</pre>

                              <div class="method-source-code" id="fdiv-source">
            <pre>static VALUE
nucomp_fdiv(VALUE self, VALUE other)
{
    return f_divide(self, other, f_fdiv, id_fdiv);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-finite-3F" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          finite?  &rarr;  true or false
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>true</code> if <code>cmp</code>‘s real and imaginary parts are both finite numbers, otherwise returns <code>false</code>.</p>

                              <div class="method-source-code" id="finite-3F-source">
            <pre>static VALUE
rb_complex_finite_p(VALUE self)
{
    get_dat1(self);

    return RBOOL(f_finite_p(dat-&gt;real) &amp;&amp; f_finite_p(dat-&gt;imag));
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-hash" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">hash</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="hash-source">
            <pre>static VALUE
nucomp_hash(VALUE self)
{
    return ST2FIX(rb_complex_hash(self));
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-imag" class="method-detail method-alias">
                      <div class="method-heading">
                        <span class="method-callseq">
                          imag       &rarr;  real
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Returns the imaginary part.</p>

<pre class="ruby"><span class="ruby-constant">Complex</span>(<span class="ruby-value">7</span>).<span class="ruby-identifier">imaginary</span>      <span class="ruby-comment">#=&gt; 0</span>
<span class="ruby-constant">Complex</span>(<span class="ruby-value">9</span>, <span class="ruby-value">-4</span>).<span class="ruby-identifier">imaginary</span>  <span class="ruby-comment">#=&gt; -4</span>
</pre>

                            </div>


                            <div class="aliases">
                              Alias for: <a href="Complex.html#method-i-imaginary">imaginary</a>
                            </div>
                          </div>

                  <div id="method-i-imaginary" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">imaginary</span><span
                                class="method-args">  -&gt;  real</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the imaginary part.</p>

<pre class="ruby"><span class="ruby-constant">Complex</span>(<span class="ruby-value">7</span>).<span class="ruby-identifier">imaginary</span>      <span class="ruby-comment">#=&gt; 0</span>
<span class="ruby-constant">Complex</span>(<span class="ruby-value">9</span>, <span class="ruby-value">-4</span>).<span class="ruby-identifier">imaginary</span>  <span class="ruby-comment">#=&gt; -4</span>
</pre>

                              <div class="method-source-code" id="imaginary-source">
            <pre>VALUE
rb_complex_imag(VALUE self)
{
    get_dat1(self);
    return dat-&gt;imag;
}</pre>
                              </div>
                            </div>

                            <div class="aliases">
                              Also aliased as: <a href="Complex.html#method-i-imag">imag</a>
                            </div>

                          </div>

                  <div id="method-i-infinite-3F" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          infinite?  &rarr;  nil or 1
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>1</code> if <code>cmp</code>‘s real or imaginary part is an infinite number, otherwise returns <code>nil</code>.</p>

<pre class="ruby"><span class="ruby-constant">For</span> <span class="ruby-value">example:</span>

   (<span class="ruby-value">1</span><span class="ruby-value">+1i</span>).<span class="ruby-identifier">infinite?</span>                   <span class="ruby-comment">#=&gt; nil</span>
   (<span class="ruby-constant">Float</span><span class="ruby-operator">::</span><span class="ruby-constant">INFINITY</span> <span class="ruby-operator">+</span> <span class="ruby-value">1i</span>).<span class="ruby-identifier">infinite?</span>   <span class="ruby-comment">#=&gt; 1</span>
</pre>

                              <div class="method-source-code" id="infinite-3F-source">
            <pre>static VALUE
rb_complex_infinite_p(VALUE self)
{
    get_dat1(self);

    if (!f_infinite_p(dat-&gt;real) &amp;&amp; !f_infinite_p(dat-&gt;imag)) {
        return Qnil;
    }
    return ONE;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-inspect" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          inspect  &rarr;  string
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the value as a string for inspection.</p>

<pre class="ruby"><span class="ruby-constant">Complex</span>(<span class="ruby-value">2</span>).<span class="ruby-identifier">inspect</span>                       <span class="ruby-comment">#=&gt; &quot;(2+0i)&quot;</span>
<span class="ruby-constant">Complex</span>(<span class="ruby-string">&#39;-8/6&#39;</span>).<span class="ruby-identifier">inspect</span>                  <span class="ruby-comment">#=&gt; &quot;((-4/3)+0i)&quot;</span>
<span class="ruby-constant">Complex</span>(<span class="ruby-string">&#39;1/2i&#39;</span>).<span class="ruby-identifier">inspect</span>                  <span class="ruby-comment">#=&gt; &quot;(0+(1/2)*i)&quot;</span>
<span class="ruby-constant">Complex</span>(<span class="ruby-value">0</span>, <span class="ruby-constant">Float</span><span class="ruby-operator">::</span><span class="ruby-constant">INFINITY</span>).<span class="ruby-identifier">inspect</span>      <span class="ruby-comment">#=&gt; &quot;(0+Infinity*i)&quot;</span>
<span class="ruby-constant">Complex</span>(<span class="ruby-constant">Float</span><span class="ruby-operator">::</span><span class="ruby-constant">NAN</span>, <span class="ruby-constant">Float</span><span class="ruby-operator">::</span><span class="ruby-constant">NAN</span>).<span class="ruby-identifier">inspect</span>  <span class="ruby-comment">#=&gt; &quot;(NaN+NaN*i)&quot;</span>
</pre>

                              <div class="method-source-code" id="inspect-source">
            <pre>static VALUE
nucomp_inspect(VALUE self)
{
    VALUE s;

    s = rb_usascii_str_new2(&quot;(&quot;);
    rb_str_concat(s, f_format(self, rb_inspect));
    rb_str_cat2(s, &quot;)&quot;);

    return s;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-magnitude" class="method-detail method-alias">
                      <div class="method-heading">
                        <span class="method-callseq">
                          magnitude  &rarr;  real
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Returns the absolute part of its polar form.</p>

<pre class="ruby"><span class="ruby-constant">Complex</span>(<span class="ruby-value">-1</span>).<span class="ruby-identifier">abs</span>         <span class="ruby-comment">#=&gt; 1</span>
<span class="ruby-constant">Complex</span>(<span class="ruby-value">3.0</span>, <span class="ruby-value">-4.0</span>).<span class="ruby-identifier">abs</span>  <span class="ruby-comment">#=&gt; 5.0</span>
</pre>

                            </div>


                            <div class="aliases">
                              Alias for: <a href="Complex.html#method-i-abs">abs</a>
                            </div>
                          </div>

                  <div id="method-i-numerator" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          numerator  &rarr;  numeric
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the numerator.</p>

<pre>    1   2       3+4i  &lt;-  numerator
    - + -i  -&gt;  ----
    2   3        6    &lt;-  denominator

c = Complex(&#39;1/2+2/3i&#39;)  #=&gt; ((1/2)+(2/3)*i)
n = c.numerator          #=&gt; (3+4i)
d = c.denominator        #=&gt; 6
n / d                    #=&gt; ((1/2)+(2/3)*i)
Complex(Rational(n.real, d), Rational(n.imag, d))
                         #=&gt; ((1/2)+(2/3)*i)</pre>

<p>See denominator.</p>

                              <div class="method-source-code" id="numerator-source">
            <pre>static VALUE
nucomp_numerator(VALUE self)
{
    VALUE cd;

    get_dat1(self);

    cd = nucomp_denominator(self);
    return f_complex_new2(CLASS_OF(self),
                          f_mul(f_numerator(dat-&gt;real),
                                f_div(cd, f_denominator(dat-&gt;real))),
                          f_mul(f_numerator(dat-&gt;imag),
                                f_div(cd, f_denominator(dat-&gt;imag))));
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-phase" class="method-detail method-alias">
                      <div class="method-heading">
                        <span class="method-callseq">
                          phase  &rarr;  float
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Returns the angle part of its polar form.</p>

<pre class="ruby"><span class="ruby-constant">Complex</span>.<span class="ruby-identifier">polar</span>(<span class="ruby-value">3</span>, <span class="ruby-constant">Math</span><span class="ruby-operator">::</span><span class="ruby-constant">PI</span><span class="ruby-operator">/</span><span class="ruby-value">2</span>).<span class="ruby-identifier">arg</span>  <span class="ruby-comment">#=&gt; 1.5707963267948966</span>
</pre>

                            </div>


                            <div class="aliases">
                              Alias for: <a href="Complex.html#method-i-arg">arg</a>
                            </div>
                          </div>

                  <div id="method-i-polar" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          polar  &rarr;  array
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns an array; [cmp.abs, cmp.arg].</p>

<pre class="ruby"><span class="ruby-constant">Complex</span>(<span class="ruby-value">1</span>, <span class="ruby-value">2</span>).<span class="ruby-identifier">polar</span>  <span class="ruby-comment">#=&gt; [2.23606797749979, 1.1071487177940904]</span>
</pre>

                              <div class="method-source-code" id="polar-source">
            <pre>static VALUE
nucomp_polar(VALUE self)
{
    return rb_assoc_new(f_abs(self), f_arg(self));
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-quo" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          cmp / numeric     &rarr;  complex
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          quo(numeric)  &rarr;  complex
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Performs division.</p>

<pre class="ruby"><span class="ruby-constant">Complex</span>(<span class="ruby-value">2</span>, <span class="ruby-value">3</span>)  <span class="ruby-operator">/</span> <span class="ruby-constant">Complex</span>(<span class="ruby-value">2</span>, <span class="ruby-value">3</span>)   <span class="ruby-comment">#=&gt; ((1/1)+(0/1)*i)</span>
<span class="ruby-constant">Complex</span>(<span class="ruby-value">900</span>)   <span class="ruby-operator">/</span> <span class="ruby-constant">Complex</span>(<span class="ruby-value">1</span>)      <span class="ruby-comment">#=&gt; ((900/1)+(0/1)*i)</span>
<span class="ruby-constant">Complex</span>(<span class="ruby-value">-2</span>, <span class="ruby-value">9</span>) <span class="ruby-operator">/</span> <span class="ruby-constant">Complex</span>(<span class="ruby-value">-9</span>, <span class="ruby-value">2</span>)  <span class="ruby-comment">#=&gt; ((36/85)-(77/85)*i)</span>
<span class="ruby-constant">Complex</span>(<span class="ruby-value">9</span>, <span class="ruby-value">8</span>)  <span class="ruby-operator">/</span> <span class="ruby-value">4</span>               <span class="ruby-comment">#=&gt; ((9/4)+(2/1)*i)</span>
<span class="ruby-constant">Complex</span>(<span class="ruby-value">20</span>, <span class="ruby-value">9</span>) <span class="ruby-operator">/</span> <span class="ruby-value">9.8</span>             <span class="ruby-comment">#=&gt; (2.0408163265306123+0.9183673469387754i)</span>
</pre>

                              <div class="method-source-code" id="quo-source">
            <pre>VALUE
rb_complex_div(VALUE self, VALUE other)
{
    return f_divide(self, other, f_quo, id_quo);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-rationalize" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          rationalize([eps])  &rarr;  rational
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the value as a rational if possible (the imaginary part should be exactly zero).</p>

<pre class="ruby"><span class="ruby-constant">Complex</span>(<span class="ruby-value">1.0</span><span class="ruby-operator">/</span><span class="ruby-value">3</span>, <span class="ruby-value">0</span>).<span class="ruby-identifier">rationalize</span>  <span class="ruby-comment">#=&gt; (1/3)</span>
<span class="ruby-constant">Complex</span>(<span class="ruby-value">1</span>, <span class="ruby-value">0.0</span>).<span class="ruby-identifier">rationalize</span>    <span class="ruby-comment"># RangeError</span>
<span class="ruby-constant">Complex</span>(<span class="ruby-value">1</span>, <span class="ruby-value">2</span>).<span class="ruby-identifier">rationalize</span>      <span class="ruby-comment"># RangeError</span>
</pre>

<p>See to_r.</p>

                              <div class="method-source-code" id="rationalize-source">
            <pre>static VALUE
nucomp_rationalize(int argc, VALUE *argv, VALUE self)
{
    get_dat1(self);

    rb_check_arity(argc, 0, 1);

    if (!k_exact_zero_p(dat-&gt;imag)) {
       rb_raise(rb_eRangeError, &quot;can&#39;t convert %&quot;PRIsVALUE&quot; into Rational&quot;,
                self);
    }
    return rb_funcallv(dat-&gt;real, id_rationalize, argc, argv);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-real" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          real  &rarr;  real
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the real part.</p>

<pre class="ruby"><span class="ruby-constant">Complex</span>(<span class="ruby-value">7</span>).<span class="ruby-identifier">real</span>      <span class="ruby-comment">#=&gt; 7</span>
<span class="ruby-constant">Complex</span>(<span class="ruby-value">9</span>, <span class="ruby-value">-4</span>).<span class="ruby-identifier">real</span>  <span class="ruby-comment">#=&gt; 9</span>
</pre>

                              <div class="method-source-code" id="real-source">
            <pre>VALUE
rb_complex_real(VALUE self)
{
    get_dat1(self);
    return dat-&gt;real;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-real-3F" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          Complex(1).real?     &rarr;  false
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          Complex(1, 2).real?  &rarr;  false
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Returns false, even if the complex number has no imaginary part.</p>

                              <div class="method-source-code" id="real-3F-source">
            <pre>static VALUE
nucomp_real_p_m(VALUE self)
{
    return Qfalse;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-rect" class="method-detail method-alias">
                      <div class="method-heading">
                        <span class="method-callseq">
                          rect         &rarr;  array
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Returns a complex object which denotes the given rectangular form.</p>

<pre class="ruby"><span class="ruby-constant">Complex</span>.<span class="ruby-identifier">rectangular</span>(<span class="ruby-value">1</span>, <span class="ruby-value">2</span>)  <span class="ruby-comment">#=&gt; (1+2i)</span>
</pre>

                            </div>


                            <div class="aliases">
                              Alias for: <a href="Complex.html#method-i-rectangular">rectangular</a>
                            </div>
                          </div>

                  <div id="method-i-rectangular" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">rectangular</span><span
                                class="method-args">  -&gt;  array</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns an array; [cmp.real, cmp.imag].</p>

<pre class="ruby"><span class="ruby-constant">Complex</span>(<span class="ruby-value">1</span>, <span class="ruby-value">2</span>).<span class="ruby-identifier">rectangular</span>  <span class="ruby-comment">#=&gt; [1, 2]</span>
</pre>

                              <div class="method-source-code" id="rectangular-source">
            <pre>static VALUE
nucomp_rect(VALUE self)
{
    get_dat1(self);
    return rb_assoc_new(dat-&gt;real, dat-&gt;imag);
}</pre>
                              </div>
                            </div>

                            <div class="aliases">
                              Also aliased as: <a href="Complex.html#method-i-rect">rect</a>, rect
                            </div>

                          </div>

                  <div id="method-i-to_c" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          to_c  &rarr;  self
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns self.</p>

<pre class="ruby"><span class="ruby-constant">Complex</span>(<span class="ruby-value">2</span>).<span class="ruby-identifier">to_c</span>      <span class="ruby-comment">#=&gt; (2+0i)</span>
<span class="ruby-constant">Complex</span>(<span class="ruby-value">-8</span>, <span class="ruby-value">6</span>).<span class="ruby-identifier">to_c</span>  <span class="ruby-comment">#=&gt; (-8+6i)</span>
</pre>

                              <div class="method-source-code" id="to_c-source">
            <pre>static VALUE
nucomp_to_c(VALUE self)
{
    return self;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-to_f" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          to_f  &rarr;  float
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the value as a float if possible (the imaginary part should be exactly zero).</p>

<pre class="ruby"><span class="ruby-constant">Complex</span>(<span class="ruby-value">1</span>, <span class="ruby-value">0</span>).<span class="ruby-identifier">to_f</span>    <span class="ruby-comment">#=&gt; 1.0</span>
<span class="ruby-constant">Complex</span>(<span class="ruby-value">1</span>, <span class="ruby-value">0.0</span>).<span class="ruby-identifier">to_f</span>  <span class="ruby-comment"># RangeError</span>
<span class="ruby-constant">Complex</span>(<span class="ruby-value">1</span>, <span class="ruby-value">2</span>).<span class="ruby-identifier">to_f</span>    <span class="ruby-comment"># RangeError</span>
</pre>

                              <div class="method-source-code" id="to_f-source">
            <pre>static VALUE
nucomp_to_f(VALUE self)
{
    get_dat1(self);

    if (!k_exact_zero_p(dat-&gt;imag)) {
        rb_raise(rb_eRangeError, &quot;can&#39;t convert %&quot;PRIsVALUE&quot; into Float&quot;,
                 self);
    }
    return f_to_f(dat-&gt;real);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-to_i" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          to_i  &rarr;  integer
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the value as an integer if possible (the imaginary part should be exactly zero).</p>

<pre class="ruby"><span class="ruby-constant">Complex</span>(<span class="ruby-value">1</span>, <span class="ruby-value">0</span>).<span class="ruby-identifier">to_i</span>    <span class="ruby-comment">#=&gt; 1</span>
<span class="ruby-constant">Complex</span>(<span class="ruby-value">1</span>, <span class="ruby-value">0.0</span>).<span class="ruby-identifier">to_i</span>  <span class="ruby-comment"># RangeError</span>
<span class="ruby-constant">Complex</span>(<span class="ruby-value">1</span>, <span class="ruby-value">2</span>).<span class="ruby-identifier">to_i</span>    <span class="ruby-comment"># RangeError</span>
</pre>

                              <div class="method-source-code" id="to_i-source">
            <pre>static VALUE
nucomp_to_i(VALUE self)
{
    get_dat1(self);

    if (!k_exact_zero_p(dat-&gt;imag)) {
        rb_raise(rb_eRangeError, &quot;can&#39;t convert %&quot;PRIsVALUE&quot; into Integer&quot;,
                 self);
    }
    return f_to_i(dat-&gt;real);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-to_r" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          to_r  &rarr;  rational
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the value as a rational if possible (the imaginary part should be exactly zero).</p>

<pre class="ruby"><span class="ruby-constant">Complex</span>(<span class="ruby-value">1</span>, <span class="ruby-value">0</span>).<span class="ruby-identifier">to_r</span>    <span class="ruby-comment">#=&gt; (1/1)</span>
<span class="ruby-constant">Complex</span>(<span class="ruby-value">1</span>, <span class="ruby-value">0.0</span>).<span class="ruby-identifier">to_r</span>  <span class="ruby-comment"># RangeError</span>
<span class="ruby-constant">Complex</span>(<span class="ruby-value">1</span>, <span class="ruby-value">2</span>).<span class="ruby-identifier">to_r</span>    <span class="ruby-comment"># RangeError</span>
</pre>

<p>See rationalize.</p>

                              <div class="method-source-code" id="to_r-source">
            <pre>static VALUE
nucomp_to_r(VALUE self)
{
    get_dat1(self);

    if (!k_exact_zero_p(dat-&gt;imag)) {
        rb_raise(rb_eRangeError, &quot;can&#39;t convert %&quot;PRIsVALUE&quot; into Rational&quot;,
                 self);
    }
    return f_to_r(dat-&gt;real);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-to_s" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          to_s  &rarr;  string
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the value as a string.</p>

<pre class="ruby"><span class="ruby-constant">Complex</span>(<span class="ruby-value">2</span>).<span class="ruby-identifier">to_s</span>                       <span class="ruby-comment">#=&gt; &quot;2+0i&quot;</span>
<span class="ruby-constant">Complex</span>(<span class="ruby-string">&#39;-8/6&#39;</span>).<span class="ruby-identifier">to_s</span>                  <span class="ruby-comment">#=&gt; &quot;-4/3+0i&quot;</span>
<span class="ruby-constant">Complex</span>(<span class="ruby-string">&#39;1/2i&#39;</span>).<span class="ruby-identifier">to_s</span>                  <span class="ruby-comment">#=&gt; &quot;0+1/2i&quot;</span>
<span class="ruby-constant">Complex</span>(<span class="ruby-value">0</span>, <span class="ruby-constant">Float</span><span class="ruby-operator">::</span><span class="ruby-constant">INFINITY</span>).<span class="ruby-identifier">to_s</span>      <span class="ruby-comment">#=&gt; &quot;0+Infinity*i&quot;</span>
<span class="ruby-constant">Complex</span>(<span class="ruby-constant">Float</span><span class="ruby-operator">::</span><span class="ruby-constant">NAN</span>, <span class="ruby-constant">Float</span><span class="ruby-operator">::</span><span class="ruby-constant">NAN</span>).<span class="ruby-identifier">to_s</span>  <span class="ruby-comment">#=&gt; &quot;NaN+NaN*i&quot;</span>
</pre>

                              <div class="method-source-code" id="to_s-source">
            <pre>static VALUE
nucomp_to_s(VALUE self)
{
    return f_format(self, rb_String);
}</pre>
                              </div>
                            </div>


                          </div>

                          </section>

              </section>
              </main>



            </div>  <!--  class='wrapper hdiv' -->


<footer id="validator-badges" role="contentinfo">
<p><a href="https://validator.w3.org/check/referer">Validate</a></p>
<p>Generated by <a href="https://ruby.github.io/rdoc/">RDoc</a> 6.4.0.</p>
<p>Based on <a href="https://github.com/ged/darkfish/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.</p>

  
    <p><p><a href="https://ruby-doc.org">Ruby-doc.org</a> is a service of <a href="https://jamesbritt.com">James Britt</a> and <a href="https://neurogami.com">Neurogami</a>, purveyors of fine <a href='https://jamesbritt.bandcamp.com/'>dance noise</a></p>
</p>
  
  </footer>

<script type="text/javascript">


  let ads  = $("#carbonads-container").children().detach();


  function swapMode() {
    var cookieName = 'darkmode';
    var cssDarkmode = Cookies.get(cookieName);
    console.log("***** swapMode! " + cssDarkmode + " *****");


    if (cssDarkmode == "true") {
      console.log("We have dark mode, set the css to light ...");
      $('#rdoccss').attr("href", defaultModeCssHref);
      $('#cssSelect').text("Dark mode");
      cssDarkmode = "false";
      console.log("swapMode! Now set cookie to " + cssDarkmode);
      Cookies.set(cookieName, cssDarkmode);

    } else {
      console.log("We not have dark mode, set the css to dark ...");
      $('#rdoccss').attr("href", darkModeCsseHref);
      $('#cssSelect').text("Light mode");
      cssDarkmode = "true";
      console.log("swapMode! Now set cookie to " + cssDarkmode);
      Cookies.set(cookieName, cssDarkmode);

    }

    console.log("  --------------- ");
  }


const vueCssApp = new Vue({
el: '#menubar',
data: {
isDark: false
},
methods: {
toggleClass: function(event){
this.isDark = !this.isDark;
}
}
})

const vueApp = new Vue({
el: '#vapp',
data: { 
isOpen: true
},

mounted() {
this.handleResize();
this.manage_mob_classes();
window.addEventListener('resize', this.handleResize)
//this.isOpen !=  (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
},
destroyed() {
window.removeEventListener('resize', this.handleResize)
},
created() {
//manage_mob_classes();
},

methods : {
isMobile() {
  return (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
},

  handleResize() {
    if (!this.isMobile()) {
      this.isOpen = window.innerWidth > 800;
    }
  },

  manage_mob_classes() {
    if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
      $("nav").addClass("mob_nav");
      $("main").addClass("mob_main");
      $("#extraz").addClass("mob_extraz");
      $("#carbonads-container").addClass("mob_carbonads-container");
      this.isOpen  = false;
    } else {
      $("nav").removeClass("mob_nav") 
        $("main").removeClass("mob_main");
      $("#extraz").removeClass("mob_extraz");
      $("#carbonads-container").removeClass("mob_carbonads-container");
      this.isOpen  = true;
    }
  },

  toggleNav() {
    this.isOpen =! this.isOpen ;
    // alert("Toggle nav!");
    console.log("toggleNav() click: " + this.isOpen );
  }
}
})

$("#carbonads-container").append(ads);


$(function() {

    var darkmode = Cookies.get("darkmode");
    console.log("Document ready: " + darkmode);

    if ( darkmode  == "true" ) {
      $('#cssSelect').text("Light mode");
    } else {
      $('#cssSelect').text("Dark mode");
     }

    $('body').css('display','block');
    });

</script>

    
  </body> 
</html>

